import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:qianyi/entity/message/Message.dart';
import 'package:qianyi/state/token.dart';

import '../../../entity/message/inner/FollowEntity.dart';
import '../../../entity/message/inner/LikeAndCollectEntity.dart';
import '../../../network/http_config.dart';
import '../../../network/http_entity.dart';
import '../../../network/http_manager.dart';
import '../../../ui/widget/custom_refresh_mixin.dart';


class FollowViewModel extends ChangeNotifier with CustomRefreshMixin{

  TextEditingController introduceController = TextEditingController();
  TokenController tokenController = Get.find();
  @override
  Future<List> requestList(int page) async {
    List tempL = [];
    Map<String, dynamic> params = {};

    // String id = UserManager.userEntity!.userInfo!.id!;

    params["uid"] = tokenController.uid;;
    params['type'] = 0;
    HttpEntity? result = await HttpManager.getInstance().request(url: "/platform/follow/getAllFriend/${page}/10", params: params,method: Method.get) as HttpEntity;
      if(result.getOriData()['code'] == 201) {
        return tempL;
      };
    FollowItemList listResult = FollowItemList.fromJson(result.getOriData()["data"]["records"]);
      List<FollowItem>? temps = listResult.items!; // 这里不需要强制类型转换
      if (temps != null) {
        tempL.addAll(temps);
      }


    return tempL;
  }


  @override
  void onRequestComplete() {
    notifyListeners();
  }

  void onrefreshXt() {
    this.onRefresh();
    notifyListeners();
  }

}

class FollowViewModel1 extends ChangeNotifier with CustomRefreshMixin{

  TextEditingController introduceController = TextEditingController();
  TokenController tokenController = Get.find();
  @override
  Future<List> requestList(int page) async {
    List tempL = [];
    Map<String, dynamic> params = {};

    // String id = UserManager.userEntity!.userInfo!.id!;

    params["uid"] = tokenController.uid;;
    params['type'] = 1;
    HttpEntity? result = await HttpManager.getInstance().request(url: "/platform/follow/getAllFriend/${page}/10", params: params,method: Method.get) as HttpEntity;
    if(result.getOriData()['code'] == 201) {
      return tempL;
    };
    FollowItemList listResult = FollowItemList.fromJson(result.getOriData()["data"]["records"]);
    List<FollowItem>? temps = listResult.items!; // 这里不需要强制类型转换
    if (temps != null) {
      tempL.addAll(temps);
    }


    return tempL;
  }


  @override
  void onRequestComplete() {
    notifyListeners();
  }

  void onrefreshXt() {
    this.onRefresh();
    notifyListeners();
  }

}